#pragma once

class CTCPAnalyser
{
protected:
	struct TPeer
	{
		u_long addr;
		u_short port;

		bool operator==(const TPeer& p) const { return addr == p.addr && port == p.port; }
	};

	struct TSocket { TPeer src, dest; };

	void TCPAnalyse(u_long ip_src, u_long ip_dest, const u_char* data, u_long size);

	struct ISocket
	{
		virtual ~ISocket() { }
		virtual void OnTCPSend(const u_char* data, u_long offset, u_long size) { }
		virtual void OnTCPReceive(const u_char* data, u_long offset, u_long size) { }
		virtual void OnTCPError() { }
	};

	virtual ISocket* OnTCPConnect(TSocket socket) { return NULL; }

private:
	struct TConnection
	{
		TSocket socket;
		u_long upIsn, downIsn;
		ISocket* object;
		CArray<u_char, u_char> upData, downData;
		u_long upLen, downLen, sendLen, receiveLen;

		void TrySend();
		void TryReceive();
	};

	CList<TConnection*> mConnections;
};
